package net.cyue.web.easyquery.core.http.handler;

import net.cyue.web.easyquery.core.db.data.PageQueryResult;
import net.cyue.web.easyquery.core.http.data.DefaultWebPageResult;
import net.cyue.web.easyquery.core.http.data.DefaultWebResult;
import net.cyue.web.easyquery.core.http.handler.api.IWebResultHandler;

import java.util.List;
import java.util.Map;

/**
 * 默认结果处理器
 */
public class DefaultWebResultHandler implements IWebResultHandler {

    @Override
    public Object handleQuery(List<Map<String, Object>> queryResult) {
        return DefaultWebResult.success("success", queryResult);
    }

    @Override
    public Object handleQueryOne(Map<String, Object> queryResult) {
        return DefaultWebResult.success("success", queryResult);
    }

    @Override
    public Object handlePageQuery(PageQueryResult pageResult) {
        return DefaultWebPageResult.success(
            "success",
            pageResult.getResult(),
            pageResult.getPage()
        );
    }

    @Override
    public Object handleUpdate(int updateCount) {
        return DefaultWebResult.success("success", updateCount);
    }
}
